﻿/**
* Copyright (C) 2014-2050 SOUI团队
* All rights reserved.
*
* @file       SStylePool.h
* @brief      SkinObj Pool
* @version    v1.0
* @author     soui
* @date       2014-05-28
*
* Describe    管理Style
*/

#pragma once
#include "core/SSingletonMap.h"
#include <unknown/obj-ref-i.h>
#include <unknown/obj-ref-impl.hpp>


//获得StylePoolMgr指针
#define GETSTYLEPOOLMGR SOUI::SStylePoolMgr::getSingletonPtr()
//通过NAME获得对应的Style
//p1: name of style
//p2: output of style
#define GETSTYLE(p) SOUI::SStylePoolMgr::getSingleton().GetStyle(p)

namespace SOUI {

    class XStylePoolImpl;
    class XStylePool {
      public:
        XStylePool();
        ~XStylePool();
        
      public:
        /**
         * GetStyle
         * @brief    Get style object from pool by class name
         * @param    LPCWSTR lpszName --  name of style
         * @param [out]  SwndStyle & style --  style
         * @return   BOOL -- TRUE: success; FALSE: not exist
         * Describe
         */
        pugi::xml_node GetStyle(LPCWSTR lpszName);
        
        /**
         * Init
         * @brief    Load Style table from xml node
         * @param    pugi::xml_node xmlNode --  xml node that describe style list
         * @return   BOOL -- TRUE: loaded; FALSE:failed;
         * Describe
         */
        BOOL Init(pugi::xml_node xmlNode);
        
      private:
        XStylePoolImpl *m_pImpl = nullptr;
    };
    
    
    class XTemplatePoolImpl;
    
    class  XTemplatePool {
      public:
        XTemplatePool();
        ~XTemplatePool();
      public:
        BOOL Init(pugi::xml_node xmlNode);
        SStringW GetTemplateString(const SStringW &strName) const;
      private:
        XTemplatePoolImpl *m_pImpl = nullptr;
    };
    
    /**
    * @class      SStylePoolMgr
    * @brief      SwndStyle的映射表的列表
    *
    * Describe
    */
    class SOUI_EXP SStylePoolMgr : public SSingleton2<SStylePoolMgr> {
        SINGLETON2_TYPE(SINGLETON_STYLEPOOLMGR)
      public:
        ~SStylePoolMgr();
        
        /**
        * GetStyle
        * @brief    Get style object from pool by class name
        * @param    LPCWSTR lpszName --  name of style
        * @param [out]  SwndStyle & style --  style
        * @return   BOOL -- TRUE: success; FALSE: not exist
        * Describe
        */
        pugi::xml_node GetStyle(LPCWSTR lpszName);
        
        BOOL Init(pugi::xml_node xmlNode);
        void Reset();
        
      protected:
        XStylePool          m_stylePool;
    };
    
    
    
    class SOUI_EXP STemplatePoolMgr : public SSingleton2<STemplatePoolMgr> {
        SINGLETON2_TYPE(SINGLETON_TEMPLATEPOOLMGR)
      public:
        ~STemplatePoolMgr();
        
        /**
        * GetTemplateString
        * @brief    Get style object from pool by class name
        * @param    const SStringW & strName --  name of template
        * @param [out]  SwndStyle & style --  style
        * @return   BOOL -- TRUE: success; FALSE: not exist
        * Describe
        */
        SStringW GetTemplateString(const SStringW &strName);
        
        BOOL Init(pugi::xml_node xmlNode);
        void Reset();
      protected:
      
        XTemplatePool m_templatePool;
    };
    
    
    
    
}//end of namespace SOUI
